//
//  HXTFuLiConsumVC.m
//  掌上宏力
//
//  Created by admin on 2017/6/14.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "HXTFuLiConsumVC.h"
#import "HXTFLConsumModel.h"
#import "HXTConsumCell.h"
#import "HXTFLConsumViewModel.h"

@interface HXTFuLiConsumVC ()

@property (nonatomic,strong) HXTFLConsumViewModel *viewModel;
@property (nonatomic,strong) NSMutableArray *datasArray;

@end

@implementation HXTFuLiConsumVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"福利领取明细";
}

-(void)getDatasArray{
    [self getDatasArray:^(NSString *page, GetDatas handler) {
        _viewModel = [[HXTFLConsumViewModel alloc] init];
        [_viewModel getHXTFLConsumWithPage:page success:^{
            if (self.currentPage == 1) {
                _datasArray = [NSMutableArray arrayWithArray:_viewModel.datasArray];
            }else{
                [_datasArray addObjectsFromArray:_viewModel.datasArray];
            }
            handler(_viewModel.datasArray);
        }];
    }];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 130;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _datasArray.count;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    HXTFLConsumModel *model = _datasArray[section];
    NSString *dateStr = model.date;
    return [dateStr substringToIndex:dateStr.length-10];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HXTConsumCell *cell = [HXTConsumCell cellWithTableView:tableView];
    HXTFLConsumModel *model = _datasArray[indexPath.section];
    cell.model = model;
    return cell;
}


@end
